package com.ktgj.customer.service.impl;

import java.util.List;

import com.ktgj.customer.domain.CaseClaim;
import com.ktgj.customer.domain.GuaranteeCase;
import com.ktgj.customer.domain.vo.GuaranteeCaseParameterVo;
import com.ktgj.customer.mapper.GuaranteeCaseMapper;
import com.ktgj.customer.service.IGuaranteeCaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.CaseMalfeasanceMapper;
import com.ktgj.customer.domain.CaseMalfeasance;
import com.ktgj.customer.service.ICaseMalfeasanceService;

import javax.annotation.Resource;

/**
 * 渎失职工单Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-05-25
 */
@Service
public class CaseMalfeasanceServiceImpl implements ICaseMalfeasanceService 
{
    @Autowired
    private CaseMalfeasanceMapper caseMalfeasanceMapper;
    @Resource
    private GuaranteeCaseMapper guaranteeCaseMapper;
    @Resource
    private IGuaranteeCaseService guaranteeCaseService;

    /**
     * 查询渎失职工单
     * 
     * @param caseMalfeasanceId 渎失职工单ID
     * @return 渎失职工单
     */
    @Override
    public CaseMalfeasance selectCaseMalfeasanceById(Long caseMalfeasanceId)
    {
        GuaranteeCase guaranteeCase = guaranteeCaseMapper.selectCaseMalfeasanceById(caseMalfeasanceId);
        CaseMalfeasance caseMalfeasance = caseMalfeasanceMapper.selectCaseMalfeasanceById(caseMalfeasanceId);
        caseMalfeasance.setCaseId(guaranteeCase.getCaseId());
        try
        {
            GuaranteeCaseParameterVo guaranteeCaseParameterVo = guaranteeCaseService.backGuaranteeCaseById(guaranteeCase.getCaseId());
            caseMalfeasance.setGuaranteeCase(guaranteeCaseParameterVo);
        } catch (Exception e)
        {
            e.printStackTrace();
        }
        return caseMalfeasance;
    }

    /**
     * 查询渎失职工单列表
     * 
     * @param caseMalfeasance 渎失职工单
     * @return 渎失职工单
     */
    @Override
    public List<CaseMalfeasance> selectCaseMalfeasanceList(CaseMalfeasance caseMalfeasance)
    {
        return caseMalfeasanceMapper.selectCaseMalfeasanceList(caseMalfeasance);
    }

    /**
     * 新增渎失职工单
     * 
     * @param caseMalfeasance 渎失职工单
     * @return 结果
     */
    @Override
    public int insertCaseMalfeasance(CaseMalfeasance caseMalfeasance)
    {
        return caseMalfeasanceMapper.insertCaseMalfeasance(caseMalfeasance);
    }

    /**
     * 修改渎失职工单
     * 
     * @param caseMalfeasance 渎失职工单
     * @return 结果
     */
    @Override
    public int updateCaseMalfeasance(CaseMalfeasance caseMalfeasance)
    {
        if (caseMalfeasance.getGuaranteeCase() != null)
        {
            GuaranteeCaseParameterVo guaranteeCaseParameterVo = caseMalfeasance.getGuaranteeCase();
            GuaranteeCase guaranteeCase = new GuaranteeCase();
            guaranteeCase.setCaseStatus(Long.valueOf(guaranteeCaseParameterVo.getWorkOrderStatus()));
            guaranteeCase.setCaseId(guaranteeCaseParameterVo.getCaseId());
            guaranteeCaseService.updateGuaranteeCase(guaranteeCase);
        }
        return caseMalfeasanceMapper.updateCaseMalfeasance(caseMalfeasance);
    }

    /**
     * 批量删除渎失职工单
     * 
     * @param caseMalfeasanceIds 需要删除的渎失职工单ID
     * @return 结果
     */
    @Override
    public int deleteCaseMalfeasanceByIds(Long[] caseMalfeasanceIds)
    {
        return caseMalfeasanceMapper.deleteCaseMalfeasanceByIds(caseMalfeasanceIds);
    }

    /**
     * 删除渎失职工单信息
     * 
     * @param caseMalfeasanceId 渎失职工单ID
     * @return 结果
     */
    @Override
    public int deleteCaseMalfeasanceById(Long caseMalfeasanceId)
    {
        return caseMalfeasanceMapper.deleteCaseMalfeasanceById(caseMalfeasanceId);
    }
}
